package playground;

import java.io.File;
import java.io.FilenameFilter;


import org.farng.mp3.MP3File;
import org.farng.mp3.id3.ID3v1;







public class ReadFileFromDiskWithID3 {

	public ReadFileFromDiskWithID3(){

	}

	public static void main(String[] args) {
		
		String path = "/Users/hali/audiotechnik_testkorpus";

		// Read A Dir

		File dir = new File(path); 
		String[] fileList = dir.list(new FilenameFilter() { // Create list of strings of all filenames
			public boolean accept(File d, String name) {
				return name.endsWith(".mp3");
			}
		});

		for(String f : fileList) {
			File sourceFile = new File(path+"/"+f);
			System.out.println("Datei eingelesen: "+sourceFile.getAbsolutePath());
			try {
				MP3File mp3file = new MP3File(sourceFile); // TODO range 4 exception? bug in jid3lib?
				ID3v1 tag = mp3file.getID3v1Tag();
				System.out.println("ID3-Tag ausgelesen : "+tag.getArtist()+" / "+tag.getTitle()+" / "+tag.getAlbum());

			} catch (Exception e) {
				System.err.println("Fehler: "+e.getMessage());
			} 
		}




	}





}
